import storage from 'good-storage'

/**
 * 设置本地存储
 * @param key
 * @param value
 */
export function saveStorage<T> (key: string, value?: T): T | undefined {
  storage.set(key, value)
  return value
}

/**
 * 获取本地存储
 * @param key
 * @param defaultValue
 */
export function loadStorage<T> (key: string, defaultValue?: T): T {
  return storage.get(key, defaultValue)
}

/**
 * 删除本地存储
 * @param key
 */
export function removeStorage (key: string): void {
  storage.remove(key)
}

/**
 * 保存会话存储
 * @param key
 * @param value
 */
export function saveSessionStorage<T> (key: string, value?: T): T | undefined {
  storage.session.set(key, value)
  return value
}

/**
 * 获取会话存储
 * @param key
 * @param defaultValue
 */
export function loadSessionStorage<T> (key: string, defaultValue?: T): T {
  return storage.session.get(key, defaultValue)
}

/**
 * 删除会话存储
 * @param key
 */
export function removeSessionStorage (key: string): void {
  storage.session.remove(key)
}
